---
title: "Cleaning Middle East Values Study: Comparative Cross-National Study of Religious Fundamentalism, Developmental Idealism, Values, and Morality in the Middle East and North Africa"
author: "Gareth Nellis"
date: "Dec 2021"
---

# Load

```{r}
# load packages
  source("helper-packages.R")

# load all but jordan
  all_but_jordan_raw <- 
    read_dta("../raw-data/y-multi-middle-east-values-study/comparative-cross-national-study-of-religious-fundamentalism/ONRMerged 7country.dta", encoding = 'latin1')
  
# load jordan  
  jordan_raw <- 
    read_dta("../raw-data/y-multi-middle-east-values-study/comparative-cross-national-study-of-religious-fundamentalism/Jordan daa-2016.dta", encoding = 'latin1')
```

# Create a codebook for Jordan (since this isn't present on the website)

```{r eval = F}
# # codebook
#   jordan_raw %>%
#     map(~attributes(.)) %>%
#     map_chr("label", .default = NA) %>% 
#     as.data.frame() %>% 
#     rownames_to_column() %>% 
#     write.csv("../raw-data/y-multi-middle-east-values-study/comparative-cross-national-study-of-religious-fundamentalism/jordan_codebook.csv", row.names = F)
```

# Clean non-Jordan countries

```{r}
# declare dates (5 individual dates in lebanon missing)
  dates <- 
    tribble(
      ~resp_country_common, ~resp_interview_start_date, ~resp_interview_end_date,
      "Lebanon", "2011-03-31", "2011-07-31") %>% # max(all_but_jordan_clean$resp_interview_date[all_but_jordan_clean$resp_country_common=="Lebanon"], na.rm = T)
    mutate(
      resp_interview_start_date = as.Date(resp_interview_start_date),
      resp_interview_end_date = as.Date(resp_interview_end_date))

# clean
  all_but_jordan_clean <- 
    all_but_jordan_raw %>% 
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Comparative Cross-National Study of Religious Fundamentalism, Developmental Idealism, Values, and Morality in the Middle East and North Africa",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3lTiV00",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person", # confirmed

      # country (character vector; list of countries as written in original source)
        resp_country_original = to_character(Country),

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = date) %>% 
      left_join(
        dates, by = "resp_country_common") %>% 
      mutate(
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          dplyr::recode(
            as.character(v10_c),
              "1" = "Muslim",
              "2" = "Muslim",
              "3" = "Muslim",
              "4" = "Other religion",
              "5" = "Christian",
              "6" = "Other religion",
              "7" = NA_character_,
              "8" = NA_character_,
              "9" = NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(v10_c),
              "1" = "Shia",
              "2" = "Sunni",
              "3" = "Muslim (sect not otherwise specified)",
              "4" = "Druze",
              "5" = "Christian",
              "6" = "Other",
              "7" = NA_character_,
              "8" = NA_character_,
              "9" = NA_character_),

      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age =
          dplyr::recode(
            as.character(v9),
            "999" = NA_character_),

      # respondent's education level
        resp_education_original =
          case_when(
            v222 == 1 | v222a == 1 ~ "1. No formal education [No education]",
            v222 == 2 | v222a == 2 ~ "2. Incomplete primary school [No education]",
            v222 == 3 | v222a == 3 ~ "3. Complete primary school [Primary]",
            v222 == 4 | v222a == 4 ~ "4. Incomplete secondary school: technical/vocational type [Primary]",
            v222 == 5 | v222a == 5 ~ "5. Complete secondary school: technical/vocational type [Primary]",
            v222 == 6 | v222a == 6 ~ "6. Incomplete secondary: university-preparatory type [Primary]",
            v222 == 7 | v222a == 7 ~ "7. Complete secondary: university-preparatory type [Primary]",
            v222 == 8 | v222a == 8 ~ "8. Some university-level education, without a degree [Primary]",
            v222 == 9 | v222a == 9 ~ "9. University-level education, with degree (include post-graduate education) [College]",
            TRUE ~ NA_character_),      
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            v233 == 2 ~ 1,
            v233 == 1 ~ 0,
            TRUE ~ NA_real_),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural = # AREA has much missingness; switched to v256 size of town
          case_when(
            #1,2,3 (rural) 4, 5, 6, 7, 8
            v256 %in% c(4, 5, 6, 7, 8) ~ 0,
            v256 %in% c(1, 2, 3) ~ 1,
            TRUE ~ NA_real_) ,
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: v207; QTEXT: On this list are various groups of people. Could you please sort out any that you would not like to have as neighbors? Sunnis.; ROPTIONS: 1 = Don't like [=1] + 2 = Like [=0]; TARGET: Sunni; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(v207),
            "8" = NA_character_,
            "9" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            v207 %in% c(1) & resp_country_original != "Tunisia" ~ 1, # "salafis" for tunisia, which is different
            v207 %in% c(2) & resp_country_original != "Tunisia" ~ 0, # "salafis" for tunisia, which is different
            TRUE ~ NA_real_), # salafis excluded: school of thought rather than distinct sect

    #########################  
    ### SOCIAL DISTANCE 2 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_2_qinfo = "NUM: v209; QTEXT: On this list are various groups of people. Could you please sort out any that you would not like to have as neighbors? Shi'is.; ROPTIONS: 1 = Don't like [=1] + 2 = Like [=0]; TARGET: Shia; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_2_original =
          case_when(
            resp_country_original != "Turkey" & v209 == 1 ~ "1",
            resp_country_original != "Turkey" & v209 == 2 ~ "2",
            TRUE ~ NA_character_),

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_2_bin_recode = 
          case_when(
            resp_soc_dist_2_original == "2" ~ 0,
            resp_soc_dist_2_original == "1" ~ 1,
            TRUE ~ NA_real_),
            
    #########################  
    ### SOCIAL DISTANCE 3 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_3_qinfo = "NUM: v209; QTEXT: On this list are various groups of people. Could you please sort out any that you would not like to have as neighbors? Allawis.; ROPTIONS: 1 = Don't like [=1] + 2 = Like [=0]; TARGET: Alawi; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_3_original =
          case_when(
            resp_country_original == "Turkey" & v209 == 1 ~ "1",
            resp_country_original == "Turkey" & v209 == 2 ~ "2",
            TRUE ~ NA_character_),

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_3_bin_recode = 
          case_when(
            resp_soc_dist_3_original == "2" ~ 0,
            resp_soc_dist_3_original == "1" ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 4 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_4_qinfo = "NUM: v213; QTEXT: On this list are various groups of people. Could you please sort out any that you would not like to have as neighbors? Jews.; ROPTIONS: 1 = Don't like [=1] + 2 = Like [=0]; TARGET: Jewish; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_4_original = 
          dplyr::recode(
            as.character(v213),
            "8" = NA_character_,
            "9" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_4_bin_recode = 
          case_when(
            v213 %in% c(2) ~ 0,
            v213 %in% c(1) ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 5 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_5_qinfo = "NUM: v214; QTEXT: On this list are various groups of people. Could you please sort out any that you would not like to have as neighbors? Christians.; ROPTIONS: 1 = Don't like [=1] + 2 = Like [=0]; TARGET: Christian; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_5_original = 
          dplyr::recode(
            as.character(v214),
            "8" = NA_character_,
            "9" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_5_bin_recode = 
          case_when(
            v214 %in% c(2) ~ 0,
            v214 %in% c(1) ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 6 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_6_qinfo = "NUM: v219; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Shi'is.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Shia; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_6_original = 
          case_when(
            resp_country_common != "Turkey" & v219 == 1 ~ "1",
            resp_country_common != "Turkey" & v219 == 2 ~ "2",
            resp_country_common != "Turkey" & v219 == 3 ~ "3",
            resp_country_common != "Turkey" & v219 == 4 ~ "4",
            TRUE ~ NA_character_), # we chose to not include salafis as a separate question because we thought it is more of a school of thoughts     

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_6_bin_recode = 
          case_when(
            resp_soc_dist_6_original %in% c("1", "2") ~ 0,
            resp_soc_dist_6_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 7 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_7_qinfo = "NUM: v219; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Allawis.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Alawi; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_7_original = 
          case_when(
            resp_country_common == "Turkey" & v219 == 1 ~ "1",
            resp_country_common == "Turkey" & v219 == 2 ~ "2",
            resp_country_common == "Turkey" & v219 == 3 ~ "3",
            resp_country_common == "Turkey" & v219 == 4 ~ "4",
            TRUE ~ NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_7_bin_recode = 
          case_when(
            resp_soc_dist_7_original %in% c("1", "2") ~ 0,
            resp_soc_dist_7_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 8 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_8_qinfo = "NUM: v220; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Sunnis.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Sunni; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_8_original = 
          case_when(
            resp_country_common != "Tunisia" & v220 == 1 ~ "1",
            resp_country_common != "Tunisia" & v220 == 2 ~ "2",
            resp_country_common != "Tunisia" & v220 == 3 ~ "3",
            resp_country_common != "Tunisia" & v220 == 4 ~ "4",
            TRUE ~ NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_8_bin_recode = 
          case_when(
            resp_soc_dist_8_original %in% c("1", "2") ~ 0,
            resp_soc_dist_8_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 9 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_9_qinfo = "NUM: v221; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Christians.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Christian; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_9_original = 
          case_when(
            resp_country_common %in% c("Lebanon", "Tunisia", "Egypt") & v221 == 1 ~ "1",
            resp_country_common %in% c("Lebanon", "Tunisia", "Egypt") & v221 == 2 ~ "2",
            resp_country_common %in% c("Lebanon", "Tunisia", "Egypt") & v221 == 3 ~ "3",
            resp_country_common %in% c("Lebanon", "Tunisia", "Egypt") & v221 == 4 ~ "4",
            TRUE ~ NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_9_bin_recode = 
          case_when(
            resp_soc_dist_9_original %in% c("1", "2") ~ 0,
            resp_soc_dist_9_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 10 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_10_qinfo = "NUM: v221; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Followers of other religions.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_10_original = 
          case_when(
            resp_country_common %in% c("Iran", "Pakistan", 
                                       "Saudi Arabia", "Syria") & v221 == 1 ~ "1",
            resp_country_common %in% c("Iran", "Pakistan", 
                                       "Saudi Arabia", "Syria") & v221 == 2 ~ "2",
            resp_country_common %in% c("Iran", "Pakistan", 
                                       "Saudi Arabia", "Syria") & v221 == 3 ~ "3",
            resp_country_common %in% c("Iran", "Pakistan", 
                                       "Saudi Arabia", "Syria") & v221 == 4 ~ "4",
            TRUE ~ NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_10_bin_recode = 
          case_when(
            resp_soc_dist_10_original %in% c("1", "2") ~ 0,
            resp_soc_dist_10_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 11 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_11_qinfo = "NUM: v221b; QTEXT: I am going to name a number of groups. For each one, could you tell me how much trust, in general, you have in them: is it a great deal of trust, some trust, not very much trust or none at all? Jews.; ROPTIONS: 1 = A great deal [=0] + 2 = Some [=0] + 3 = Not very much [=1] + 4 = None at all [=1]; TARGET: Jewish; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_11_original = 
          case_when(
            resp_country_common %in% c("Tunisia") & v221b == 1 ~ "1",
            resp_country_common %in% c("Tunisia") & v221b == 2 ~ "2",
            resp_country_common %in% c("Tunisia") & v221b == 3 ~ "3",
            resp_country_common %in% c("Tunisia") & v221b == 4 ~ "4",
            TRUE ~ NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_11_bin_recode = 
          case_when(
            resp_soc_dist_11_original %in% c("1", "2") ~ 0,
            resp_soc_dist_11_original %in% c("3", "4") ~ 1,
            TRUE ~ NA_real_),

   ############################  
   ### GENERAL SOCIAL TRUST ###  
   ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked, no general trust question asked

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######  
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: v5; QTEXT: How important is religion in your life – very important, rather important, not very important, or not all important?; ROPTIONS: 1 = Very important + 2 = Rather important + 3 = Not very important + 4 = Not important at all",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(v5),
            `8` = NA_real_,
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3

    ) %>% 
    select(starts_with("resp_"))
```

# Clean Jordan

```{r}
# clean
  jordan_clean <- 
    jordan_raw %>% 
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Comparative Cross-National Study of Religious Fundamentalism, Developmental Idealism, Values, and Morality in the Middle East and North Africa",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3lTiV00",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Jordan",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = as.Date(date, "%d/ %m/ %Y"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          dplyr::recode(
            as.character(v46),
              "1" = "Muslim",
              "3" = "Christian",
              "8" = NA_character_,
              "9" = NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(v46),
              "1" = "Sunni",
              "3" = "Christian",
              "8" = NA_character_,
              "9" = NA_character_),

      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age =
          dplyr::recode(
            as.character(v6),
            "9998" = NA_character_,
            "9999" = NA_character_),

      # respondent's education level
        resp_education_original =
          case_when(
            v208 == 1 ~ "1. No formal education (illiterate) [No education]",
            v208 == 2 ~ "2. Complete primary school [Primary]",
            v208 == 3 ~ "3. Complete preparatory/essential [Primary]",
            v208 == 4 ~ "4. Complete secondary school [Primary]",
            v208 == 5 ~ "5. Diploma/vocational or technical [Primary]",
            v208 == 6 ~ "6. Bachelor degree [College]",
            v208 == 7 ~ "7. Master's degree or above [College]",
            TRUE ~ NA_character_),      
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            v220 == 2 ~ 1,
            v220 == 1 ~ 0,
            TRUE ~ NA_real_),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural = 
          case_when(
            Rural == 1 ~ 0,
            Rural == 2 ~ 1,
            TRUE ~ NA_real_
          ),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: v171; QTEXT: I am going to name a number of individuals, groups and institutions. For each one, could you tell me how much trust, in general, you have in them: is it a lot, some, only a little, or none at all? Christians.; ROPTIONS: 1 = A lot [=0] + 2 = Some [=0] + 3 = Only a little [=1] + 4 = Not at all [=1]; TARGET: Christian; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(v171),
            "98" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            v171 %in% c(1, 2) ~ 0,
            v171 %in% c(3, 4) ~ 1,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 2 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_2_qinfo = "NUM: v173; QTEXT: I am going to name a number of individuals, groups and institutions. For each one, could you tell me how much trust, in general, you have in them: is it a lot, some, only a little, or none at all? Shia.; ROPTIONS: 1 = A lot [=0] + 2 = Some [=0] + 3 = Only a little [=1] + 4 = Not at all [=1]; TARGET: Shia; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_2_original = 
          dplyr::recode(
            as.character(v173),
            "98" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_2_bin_recode = 
          case_when(
            v173 %in% c(1, 2) ~ 0,
            v173 %in% c(3, 4) ~ 1,
            TRUE ~ NA_real_),
            
    #########################  
    ### SOCIAL DISTANCE 3 ###  
    #########################

      # original question number; question text; response options (input above)
        resp_soc_dist_3_qinfo = "NUM: v174; QTEXT: I am going to name a number of individuals, groups and institutions. For each one, could you tell me how much trust, in general, you have in them: is it a lot, some, only a little, or none at all? Sunni.; ROPTIONS: 1 = A lot [=0] + 2 = Some [=0] + 3 = Only a little [=1] + 4 = Not at all [=1]; TARGET: Sunni; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_3_original = 
          dplyr::recode(
            as.character(v174),
            "98" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_3_bin_recode = 
          case_when(
            v174 %in% c(1, 2) ~ 0,
            v174 %in% c(3, 4) ~ 1,
            TRUE ~ NA_real_),
   
   ############################  
   ### GENERAL SOCIAL TRUST ###  
   ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked, no general trust question asked

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######  
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: v2; QTEXT: How important is religion in your life – very important, rather important, not very important, or not all important?; ROPTIONS: 1 = Very important + 2 = Rather important + 3 = Not very important + 4 = Not important at all",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(v2),
            `8` = NA_real_,
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3

    ) %>% 
    select(starts_with("resp_"))
```

# Stack dataframes and fix erroneous 2 dates

```{r}
  stacked <- 
    all_but_jordan_clean %>% 
    bind_rows(jordan_clean) %>%
    mutate(resp_interview_date = as.character(resp_interview_date),
           resp_interview_date = ifelse(resp_interview_date == "2031-04-24", "2013-04-24", resp_interview_date),
           resp_interview_date = ifelse(resp_interview_date == "2103-05-11", "2013-05-11", resp_interview_date),
           resp_interview_date = as.Date(resp_interview_date))
```

# Save data

```{r}
  saveRDS(stacked, "../cleaned-data/y-9-multi-middle-east-values-study-ccnsf.rds")
```
